package com.xn.app.muying.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.jumper.fetalheart.line.HeadSetUnit;
import com.xn.app.muying.R;
import com.xn.app.muying.util.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;

public class YouXianActivity extends BaseActivity {
    TextView lian_jie_ti_shi;
    Timer timer;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_you_xian);
        lian_jie_ti_shi = (TextView) findViewById(R.id.lian_jie_ti_shi);
        findViewById(R.id.guan_bi).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
         timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                // 检查耳机音频线是否有插入
                if (HeadSetUnit.checkHeadSet(YouXianActivity.this)) {
                    Message msg = new Message();
                    handler.sendMessage(msg);
                }
            }
        };
        timer.schedule(task, 1000, 1000); //2秒后
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            lian_jie_ti_shi.setText("耳机音频线已插入");
            startActivity(new Intent(YouXianActivity.this, RecordingActivity.class));
            finish();
            timer.cancel();
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onResume() {
        super.onResume();
    }
}
